/*
 * @Author: 景新然
 * @LastEditors: 景新然
 * @Date: 2021-07-13 14:52:52
 * @LastEditTime: 2021-07-13 17:23:12
 * @Description: 本地服务
 */
const cors = require("cors");
const bodyParser = require("body-parser");
const express = require("express");
const server = express();
const path = require("path");
const EventEmitter = require("events");
const Server = new EventEmitter();
const axios = require("axios");
const DataManager = require("./DataManager");
const ROOTPATH = path.join(__dirname, "../../data");
server.use(cors());
server.use(
    bodyParser.urlencoded({
        extended: false,
    })
);
server.use(bodyParser.json({ limit: '50mb' }));
server.use(bodyParser.text());
server.use(express.static(ROOTPATH));

axios.defaults.timeout = 15 * 1000;

server.get('/img', (req, res) => {
    res.send({
        code: 0,
        data: {
            frameImg: DataManager.getFrameImg().map(item => `http://localhost:8012/frame/${item}`),
            propsImg: DataManager.getPropsImg().map(item => `http://localhost:8012/prop/${item}`),
        }
    });
});

server.get('/config', (req, res) => {
    res.send({
        code: 0,
        data: DataManager.getAllConfig()
    });
})


server.listen(8012);
module.exports = Server;
